import React, { useMemo } from "react";

interface User {
  id: number;
  name: string;
  age: number;
}

const UserStats: React.FC<{ users: User[] }> = ({ users }) => {
  const averageAge = useMemo(() => {
    console.log("计算平均年龄...");
    return users.reduce((sum, user) => sum + user.age, 0) / users.length;
  }, [users]);

  return <div>平均年龄: {averageAge.toFixed(2)}</div>;
};

export default UserStats;
